package com.haidechizi.leetcode;


public class _98_验证二叉搜索树 {

    Integer pre = null;

    public boolean isValidBST(TreeNode root) {
        return postOrder(root);
    }

    public boolean postOrder(TreeNode treeNode) {
        if (treeNode == null) {
            return true;
        }



        if (!postOrder(treeNode.left)) {
            return false;
        }

        if (pre != null && pre >= treeNode.val) {
            return false;
        }

        pre = treeNode.val;

        if (!postOrder(treeNode.right)) {
            return false;
        }

        return true;

    }
}
